{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from googletrans import Translator\n",
    "translator = Translator(service_urls=[r'translate.google.cn'],user_agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36')\n",
    "#a = translator.translate('Hello',src='en',dest='zh-cn')\n",
    "#print(a.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "202\n",
      "383\n",
      "50\n",
      "345\n",
      "209\n",
      "417\n",
      "487\n",
      "241\n",
      "251\n",
      "487\n",
      "469\n",
      "454\n",
      "392\n",
      "855\n",
      "442\n",
      "5684\n",
      "[\"In this part there is an essay. Read it carefully and then write a summary of 200 words in English. Make sure that your summary covers the major points of the passage. Don't copy the original sentences.\\n\", 'Latent autoimmune diabetes of adults (LADA), otherwise known as type 1.5 diabetes, is a less common form of diabetes that affects adults, typically after 35 years of age. LADA may account for 2–12% of all cases of diabetes in the adult population. People with LADA may present with signs and symptoms of both type 1 and type 2 diabetes, which makes diagnosing LADA more challenging. \\n', 'LADA is different from type 1 and type 2 diabetes.\\n', 'Doctors typically diagnose type 1 diabetes in children and adolescents, but the peaks in its presentation occur between 5–7 years old and around puberty. In type 1, antibodies attack the cells of the pancreas. Since the pancreas cannot produce enough insulin, people with type 1 diabetes must use insulin injections to control their blood sugar.\\n', 'Type 2 diabetes is a metabolic disease that results from defective insulin action.Type 2 diabetes affects middle aged and older adults with high blood sugar due to previous lifestyle choices and eating habits.\\n', 'LADA is more similar to type 1 diabetes than type 2. This similarity may be why doctors sometimes call it type 1.5 diabetes. As with type 1 diabetes, people living with LADA typically have a lower body mass index (BMI) than people living with type 2 diabetes. LADA also presents with some characteristics of type 2 diabetes, such as older age at diagnosis and deficiencies in insulin or decreased function of insulin.\\n', 'LADA may present with very broad symptoms, such as ketoacidosis, which can cause a distinctive fruity odor on the breath and high blood sugar. Some individuals with LADA will present with symptoms of both type 1 and type 2 diabetes. These may include excessive thirst, frequent urination, excessive hunger, extreme fatigue, blurry vision, cuts and bruises that heal slowly, weight loss despite eating more (type 1), and tingling, pain, or numbness in the hands or feet (type 2 diabetes).\\n', 'The cause of LADA is the development of autoantibodies against pancreatic cells, insulin, or enzymes involved in pancreatic functions. Antibodies affecting the pancreas and its function may influence the way the body responds to blood sugar.\\n', 'Experts suggest that LADA may share come genetic features of type 1 and type 2 diabetes. This may explain why LADA shares some of the clinical features of both forms. However, researchers do not know if there are any specific genetic factors for LADA.\\n', 'Doctors have not yet established absolute guidelines for treating LADA. The goal of the treatment is to preserve the pancreatic cell function. To do so, a person can sometimes use insulin injections. Also, some antidiabetic drugs may help slow down pancreatic cell destruction, including DPP-4 inhibitors and glucagon-like peptide-1 receptor agonists. However, doctors may recommend a personalized treatment strategy, depending on each case, and the symptoms an individual is displaying.\\n', 'Similarly to type 2 diabetes, people with LADA may be at risk of microvascular complications, including kidney damage, nerve damage causing pain, tingling, and loss of sensation in the hands and feet and disorders of the eye and vision. Some experts suggest that people with LADA may have a higher chance of developing cardiovascular conditions than people with type 2 diabetes. People with LADA may have higher blood cholesterol levels than those with type 2 diabetes.\\n', 'Diabetic ketoacidosis (DKA) is another potential complication of LADA. DKA can occur when the cells are unable to receive the glucose that they need, and the body instead burns fat for energy. This can produce ketones, which are responsible for the fruity odor of the breath. DKA is a serious condition that can lead to diabetic coma. Symptoms may include signs of high blood sugar, unintentional weight loss, vomiting, weakness, changes in mental state.\\n', 'Some risk factors for developing LADA include obesity or excessive weight, low birth weight, and low physical activity. Researchers suggest that people with multiple risk factors may have higher chances of developing LADA. For example, the combination of low birth weight and adult overweight may increase the chance of LADA. Psychosocial stress may also be a risk factor for developing LADA.\\n', 'Doctors may find it challenging to tell the difference between LADA and type 2 diabetes. Some characteristics of LADA may prompt doctors to conduct further screening to help distinguish between types of diabetes. Doctors typically diagnose LADA in people over 35 years of age, which is consistent with a diagnosis of type 2 diabetes. People living with LADA may initially respond well to nutrition and lifestyle changes and oral medications, but their response usually declines. People living with LADA will test positive for at least one antibody directed against the pancreatic cells, insulin, or enzymes involved in pancreatic function. C-peptide is another factor that helps doctors distinguish between types of diabetes. People living with LADA may have low to normal blood levels of C-peptide, whereas levels are lower in type 1 and type 2 diabetes.\\n', 'People experiencing unexplained excessive thirst or hunger, or frequent urination should see a doctor. To test for diabetes, doctors will request blood tests to check several blood sugar markers. DKA may occur in people who delay seeing a doctor for symptoms of diabetes. DKA can signify that a person’s diabetes is getting worse. People should report DKA symptoms immediately to a doctor as the condition can be life threatening. (882 words)\\n']\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "context = open('3.txt',encoding='UTF8',mode='r').readlines()\n",
    "context2 = []\n",
    "count_chars = 0\n",
    "for i in context:\n",
    "    i=i.strip('\\n')\n",
    "    if i != '':\n",
    "        if len(i) > 1200:\n",
    "            for i2 in i.split('. '):\n",
    "                context2.append(i2+'. ')\n",
    "                print(len(i2))\n",
    "                count_chars += len(i2)\n",
    "            continue\n",
    "        context2.append(i+'\\n')\n",
    "        print(len(i))\n",
    "        count_chars += len(i)\n",
    "\n",
    "print(count_chars)\n",
    "print(context2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1247\n",
      "1184\n",
      "1193\n",
      "1111\n",
      "964\n",
      "5699\n",
      "[\"In this part there is an essay. Read it carefully and then write a summary of 200 words in English. Make sure that your summary covers the major points of the passage. Don't copy the original sentences.\\nLatent autoimmune diabetes of adults (LADA), otherwise known as type 1.5 diabetes, is a less common form of diabetes that affects adults, typically after 35 years of age. LADA may account for 2–12% of all cases of diabetes in the adult population. People with LADA may present with signs and symptoms of both type 1 and type 2 diabetes, which makes diagnosing LADA more challenging. \\nLADA is different from type 1 and type 2 diabetes.\\nDoctors typically diagnose type 1 diabetes in children and adolescents, but the peaks in its presentation occur between 5–7 years old and around puberty. In type 1, antibodies attack the cells of the pancreas. Since the pancreas cannot produce enough insulin, people with type 1 diabetes must use insulin injections to control their blood sugar.\\nType 2 diabetes is a metabolic disease that results from defective insulin action.Type 2 diabetes affects middle aged and older adults with high blood sugar due to previous lifestyle choices and eating habits.\\nLADA is more similar to type 1 diabetes than type 2. \", 'This similarity may be why doctors sometimes call it type 1.5 diabetes. As with type 1 diabetes, people living with LADA typically have a lower body mass index (BMI) than people living with type 2 diabetes. LADA also presents with some characteristics of type 2 diabetes, such as older age at diagnosis and deficiencies in insulin or decreased function of insulin.\\nLADA may present with very broad symptoms, such as ketoacidosis, which can cause a distinctive fruity odor on the breath and high blood sugar. Some individuals with LADA will present with symptoms of both type 1 and type 2 diabetes. These may include excessive thirst, frequent urination, excessive hunger, extreme fatigue, blurry vision, cuts and bruises that heal slowly, weight loss despite eating more (type 1), and tingling, pain, or numbness in the hands or feet (type 2 diabetes).\\nThe cause of LADA is the development of autoantibodies against pancreatic cells, insulin, or enzymes involved in pancreatic functions. Antibodies affecting the pancreas and its function may influence the way the body responds to blood sugar.\\nExperts suggest that LADA may share come genetic features of type 1 and type 2 diabetes. ', 'This may explain why LADA shares some of the clinical features of both forms. However, researchers do not know if there are any specific genetic factors for LADA.\\nDoctors have not yet established absolute guidelines for treating LADA. The goal of the treatment is to preserve the pancreatic cell function. To do so, a person can sometimes use insulin injections. Also, some antidiabetic drugs may help slow down pancreatic cell destruction, including DPP-4 inhibitors and glucagon-like peptide-1 receptor agonists. However, doctors may recommend a personalized treatment strategy, depending on each case, and the symptoms an individual is displaying.\\n\\nSimilarly to type 2 diabetes, people with LADA may be at risk of microvascular complications, including kidney damage, nerve damage causing pain, tingling, and loss of sensation in the hands and feet and disorders of the eye and vision. Some experts suggest that people with LADA may have a higher chance of developing cardiovascular conditions than people with type 2 diabetes. People with LADA may have higher blood cholesterol levels than those with type 2 diabetes.\\nDiabetic ketoacidosis (DKA) is another potential complication of LADA. ', 'DKA can occur when the cells are unable to receive the glucose that they need, and the body instead burns fat for energy. This can produce ketones, which are responsible for the fruity odor of the breath. DKA is a serious condition that can lead to diabetic coma. Symptoms may include signs of high blood sugar, unintentional weight loss, vomiting, weakness, changes in mental state.\\nSome risk factors for developing LADA include obesity or excessive weight, low birth weight, and low physical activity. Researchers suggest that people with multiple risk factors may have higher chances of developing LADA. For example, the combination of low birth weight and adult overweight may increase the chance of LADA. Psychosocial stress may also be a risk factor for developing LADA.\\nDoctors may find it challenging to tell the difference between LADA and type 2 diabetes. Some characteristics of LADA may prompt doctors to conduct further screening to help distinguish between types of diabetes. Doctors typically diagnose LADA in people over 35 years of age, which is consistent with a diagnosis of type 2 diabetes. ', 'People living with LADA may initially respond well to nutrition and lifestyle changes and oral medications, but their response usually declines. People living with LADA will test positive for at least one antibody directed against the pancreatic cells, insulin, or enzymes involved in pancreatic function. C-peptide is another factor that helps doctors distinguish between types of diabetes. People living with LADA may have low to normal blood levels of C-peptide, whereas levels are lower in type 1 and type 2 diabetes.\\nPeople experiencing unexplained excessive thirst or hunger, or frequent urination should see a doctor. To test for diabetes, doctors will request blood tests to check several blood sugar markers. DKA may occur in people who delay seeing a doctor for symptoms of diabetes. DKA can signify that a person’s diabetes is getting worse. People should report DKA symptoms immediately to a doctor as the condition can be life threatening. (882 words)']\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "context = open('3.txt',encoding='UTF8',mode='r').read()\n",
    "context2 = []\n",
    "count_chars = 0\n",
    "i_last = ''\n",
    "context=context.split('. ')\n",
    "for i in context:\n",
    "    if len(i_last) < 1100:\n",
    "        i_last = i_last + i + '. '\n",
    "        continue\n",
    "    context2.append(i_last)\n",
    "    print(len(i_last))\n",
    "    count_chars += len(i_last)\n",
    "    i_last = '' + i + '. '\n",
    "    if len(i_last) >= 1100:\n",
    "        context2.append(i_last)\n",
    "        print(len(i_last))\n",
    "        count_chars += len(i_last)\n",
    "        i_last = ''\n",
    "\n",
    "i_last=i_last.strip('\\n. ')\n",
    "context2.append(i_last)\n",
    "print(len(i_last))\n",
    "count_chars += len(i_last)\n",
    "\n",
    "print(count_chars)\n",
    "print(context2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['在这一部分中有一篇文章。仔细阅读，然后用英语写一个200字的摘要。确保您的摘要涵盖了段落的要点。不要复制原始句子。\\n成人潜伏性自身免疫性糖尿病（LADA），也称为1.5型糖尿病，是一种不常见的糖尿病，会影响成年人，通常在35岁以后。在成人人群中，LADA可能占所有糖尿病病例的2–12％。 LADA患者可能同时出现1型和2型糖尿病的体征和症状，这使LADA的诊断更具挑战性。\\nLADA与1型和2型糖尿病不同。\\n医生通常会在儿童和青少年中诊断出1型糖尿病，但其发病高峰出现在5-7岁至青春期前后。在类型1中，抗体攻击胰腺细胞。由于胰腺不能产生足够的胰岛素，因此1型糖尿病患者必须使用胰岛素注射来控制血糖。\\n2型糖尿病是一种由于胰岛素作用缺陷引起的代谢性疾病。由于以前的生活方式和饮食习惯，2型糖尿病会影响中高血糖的成年人。\\nLADA比2型更类似于1型糖尿病。', '这种相似性可能就是为什么医生有时称其为1.5型糖尿病。与1型糖尿病一样，与2型糖尿病患者相比，LADA患者通常具有较低的体重指数（BMI）。 LADA还具有2型糖尿病的某些特征，例如诊断时年龄偏大和胰岛素缺乏或胰岛素功能下降。\\nLADA可能会表现出非常广泛的症状，例如酮症酸中毒，这会导致呼吸中的果味气味和高血糖。一些患有LADA的患者会同时出现1型和2型糖尿病的症状。这些可能包括口渴，尿频，过度饥饿，极度疲劳，视力模糊，割伤和瘀伤缓慢愈合，尽管进食较多但体重减轻（1型）以及手或脚刺痛，疼痛或麻木（2型）。糖尿病）。\\nLADA的原因是针对胰腺细胞，胰岛素或涉及胰腺功能的酶的自身抗体的发展。影响胰腺及其功能的抗体可能会影响人体对血糖的反应方式。\\n专家建议，LADA可能共享1型和2型糖尿病的遗传特征。', '这可以解释为什么LADA具有两种形式的某些临床特征。但是，研究人员不知道LADA是否有任何特定的遗传因素。\\n医生尚未建立治疗LADA的绝对指南。该治疗的目的是保持胰腺细胞功能。为此，一个人有时可以使用胰岛素注射剂。同样，一些抗糖尿病药可能有助于减慢胰腺细胞的破坏，包括DPP-4抑制剂和胰高血糖素样肽1受体激动剂。但是，医生可能会根据每种情况以及个人所显示的症状，建议采取个性化的治疗策略。\\n\\n与2型糖尿病相似，患有LADA的人可能有微血管并发症的风险，包括肾脏损害，神经痛引起的疼痛，刺痛以及手脚感觉丧失以及眼和视力障碍。一些专家建议，患有LADA的人比患有2型糖尿病的人患心血管疾病的机会更高。与2型糖尿病患者相比，LADA患者的血液胆固醇水平可能更高。\\n糖尿病性酮症酸中毒（DKA）是LADA的另一潜在并发症。', '当细胞无法接收所需的葡萄糖时，就会发生DKA，而人体会燃烧脂肪获取能量。这会产生酮，这是呼吸的水果味。 DKA是一种严重疾病，可导致糖尿病昏迷。症状可能包括高血糖，无意识的体重减轻，呕吐，虚弱，精神状态改变的体征。\\n罹患LADA的一些风险因素包括肥胖或体重过重，出生时体重低和体育活动量低。研究人员建议，具有多种危险因素的人患LADA的机会可能更高。例如，低出生体重和成人超重的结合可能会增加LADA的机会。社会心理压力也可能是发展LADA的危险因素。\\n医生可能很难区分LADA和2型糖尿病。 LADA的某些特征可能促使医生进行进一步筛查，以帮助区分糖尿病类型。医生通常在35岁以上的人群中诊断出LADA，这与2型糖尿病的诊断是一致的。', '患有LADA的人最初可能对营养和生活方式的改变以及口服药物反应良好，但他们的反应通常会下降。患有LADA的人将对至少一种针对胰腺细胞，胰岛素或涉及胰腺功能的酶的抗体测试呈阳性。 C肽是另一个可以帮助医生区分糖尿病类型的因素。患有LADA的人的C肽血液水平可能低至正常，而1型和2型糖尿病的水平则较低。\\n遇到无法解释的过度口渴或饥饿或尿频的人应去看医生。为了测试糖尿病，医生会要求进行血液测试以检查几种血糖指标。 DKA可能会出现在因糖尿病症状而延迟就医的人中。 DKA可以表明一个人的糖尿病正在恶化。人们应立即向医生报告DKA症状，因为该病可能危及生命。 （882字）\\n。']\n"
     ]
    }
   ],
   "source": [
    "context3 = []\n",
    "for i3 in context2:\n",
    "    context3.append(translator.translate(i3,src='en',dest='zh-cn').text)\n",
    "print(context3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1693"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "open('3.trans.txt',encoding='UTF8',mode='w').write(''.join(context3)+'\\n')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
